#!/bin/sh
# help usage                        ./do h 
# Development-Start gcad3d          ./do

# must be started in directory ${DIR_DEV}gcad3d/src/APP/



# get DIR_DEV DIR_BIN gcad_dir_dev gcad_dir_bin
. ../options.sh

echo "gcad_dir_dev: " ${gcad_dir_dev}
echo "gcad_dir_bin: " ${gcad_dir_bin}


cmdVi=${DIR_BIN}'vi.sh'
#cmdVi='vim -N -u /mnt/serv1/Linux/bin/.vimrc'
#echo $cmdVi



if test "$1" = "help"; then
  echo "./do complete          # do all following"
  echo "./do delete            # delete all objects"
  echo "./do guiinit           # change gui-version"
  echo "./do gui               # rebuild xa_gui_gtk-*.so"
  echo "./do c                 # compile & link core"
  echo "./do all               # compile & link corelibs"
  echo "./do allDemos          # compile & link demos"
  echo "./do processes         # compile & link NC-processes"
  echo "./do fDep              # compile & link list of files (see fDep.sh)"
  echo "./do *.mak             # link a plugin (for the first time)"
  echo "./do                   # start"
  echo "./do debug             # start with debugger"
  echo "./do trc               # start with mtrace"
  echo "./do ud                # display userDoc"
  echo "./do dd                # display devDoc"
  echo "./do udd               # update & display devDoc"
  echo "./do gty               # display AP_types.h"
  echo "./do gh                # display ut_geo.h"
  echo "./do g2                # display ut_geo3d.c"
  echo "./do g3                # display ut_geo3d.c"
  echo "./do gmon              # analyze time"
  echo "./do edm               # edit model"
  echo "./do msg-files         # tools for language-files: ls lang*.csh"
  exit 0
fi


# rebuild all
if test "$1" = "complete"; then
./del_obj.sh
# create xa_gui_(VGUI).so and create link xa_gui.so <- xa_gui_(VGUI).so
./do gui-gtk2
./do gui-gtk3
# create core
./do c
# create core-dll's
./do all
# create demo-plugins
./do allDemos
exit 0
fi


if test "$1" = "delete"; then
  ./del_obj.sh
  exit 0
fi


if test "$1" = "gui-gtk2"; then
# test if gtk2 installed and set as active gui-version          
../gui_version_set.sh gtk2
if [ $? -ne 0 ] ; then
  exit 0
fi
# compile ..
./do guiinit
  exit 0
fi


if test "$1" = "gui-gtk3"; then
# test if gtk3 installed and set as active gui-version
../gui_version_set.sh gtk3
if [ $? -ne 0 ] ; then
  exit 0
fi
# compile ..
./do guiinit
  exit 0
fi



if test "$1" = "guiinit"; then
  make -f gcad_gui__.mak delete
  make -f gcad_gui_lnk.mak
  make -f gcad_gui__.mak link
  exit 0
fi


# compile active gui-lib
if test "$1" = "gui"; then
  make -f gcad_gui_lnk.mak
  make -f gcad_gui__.mak link
  exit 0
fi


# compile core; gui-libs must already exist
if test "$1" = "c"; then
  rm -f *.o
  make -f gcad3d.mak
  exit 0
fi


# build gcad3d-coreLibs
if test "$1" = "all"; then
  make -f gcad3d.mak all
  exit 0
fi


# build gcad3d-plugins
if test "$1" = "allDemos"; then
  make -f gcad3d.mak allDemos
  exit 0
fi


# build gcad3d-NC-processes
if test "$1" = "processes"; then
  make -f gcad3d.mak processes   ????
  exit 0
fi



if test "$1" = "fDep"; then
  rm -f *.o
  # create fDep.txt = list of file ; input = file t1 created by cbrowse !
  ./fDep.sh
  make -f gcad3d.mak
  exit 0
fi

if test "$1" = "ud"; then
  firefox ../../doc/html/index_de.htm 2>/dev/null &
  exit 0
fi

if test "$1" = "dd"; then
  firefox ../../doc/gcad/index.htm
  exit 0
fi

# ReCreate development-documentation (doxygen must be installed):
if test "$1" = "udd"; then
  cd ../../doc && ./gcad_doxygen.sh > t1
  exit 0
fi

if test "$1" = "gty"; then
  $cmdVi ../ut/AP_types.h
  exit 0
fi

if test "$1" = "gh"; then
  $cmdVi ../ut/ut_geo.h
  exit 0
fi

if test "$1" = "g2"; then
  $cmdVi ../ut/ut_geo2d.c
  exit 0
fi

if test "$1" = "g3"; then
  $cmdVi ../ut/ut_geo3d.c
  exit 0
fi

if test "$1" = "edm"; then
   $cmdVi "${gcad_dir_dev}gCAD3D/tmp/Model"
  exit 0
fi


# check filetyp
ftyp=`echo $1 | cut -d"." -f2-`

if test "$ftyp" = "mak"; then
  make -f $1
  exit 0
fi


#=================================================================
# start gCAD3D
# Must set gcad_dir_bin and gcad_dir_bas;


#export UBUNTU_MENUPROXY=

OSTYPE=`uname`
# "Linux" = Ubuntu 12/32
echo "start - OSTYPE = " $OSTYPE


if [ "$OSTYPE" = "Linux" ] ; then


# icons; if not set: /usr/share/gcad3d/
# export gcad_dir_bas=${gcad_dir_dev}

# executables (shared-libs ..)
# export gcad_dir_bin=${DirBasSer}/gCAD3D/binLinux${bitNr}/
# export gcad_dir_bin=${DirBasSer}/binLinux${bitNr}/
# export gcad_dir_bin=${gcad_dir_bin}
  export LD_LIBRARY_PATH=${gcad_dir_bin}

# def is /usr/share/gcad3d/
  #export gcad_dir_local=${DirBasSer}/
  export gcad_dir_local=${gcad_dir_dev}

# icons,
  export gcad_dir_ico=${gcad_dir_dev}icons/

# html and msg-files
# def is /usr/share/doc/
  export gcad_dir_doc=${gcad_dir_dev}doc/



  exeNam=${gcad_dir_bin}gCAD3D



# change configfiles to unix if last start was with MS-Windows
if [ -f MS.lock ]; then
  cfgDir=${gcad_dir_dev}gCAD3D/cfg/
  echo "set dir.lst & xa.rc -> Unix"
  /bin/cp -f ${cfgDir}dir.lst ${cfgDir}dirMS.lst
  /bin/cp -f ${cfgDir}xa.rc ${cfgDir}xaMS.rc
  /bin/cp -f ${cfgDir}dirUX.lst ${cfgDir}dir.lst
  /bin/cp -f ${cfgDir}xaUX.rc ${cfgDir}xa.rc
  /bin/rm -f MS.lock
  touch UX.lock
fi




#-----------------------------------------------------
# analyze times in file gmon.out - AFTER run gcad
if [ "$1" = "gmon" ] ; then
  gprof ${exeNam} > t1 && vi t1
  exit 0



#-----------------------------------------------------
# d = debug
elif [ "$1" = "debug" ] ; then
  gdb ${exeNam} $* -x gCAD3D.gdb
  #nemiver ${gcad_dir_bin}/gCAD3D
  exit 0


#-----------------------------------------------------
# trc ?
elif [ "$1" = "trc" ] ; then
  export MALLOC_TRACE=mtrace.txt
  ${exeNam}
  #mtrace  ${exeNam} $MALLOC_TRACE
  exit 0


#-----------------------------------------------------
fi

echo "normal start .."
# i = Init (nach MS_Windows)
#if test "$1" = "i"; then
#fi
  
#./gCAD3D.sh $*
${exeNam} $*
exit



#----------------------------------------------------
elif [ "$OSTYPE" = "msys" ] ; then
  cp -f dirw.lst dir.lst
  #cp -f xa.rc_MS ../tmp\xa.rc
  cd ..
  gdb binMS32/gCAD3D.exe $*


#-----------------------------------------------------
else
  echo "OPSYS $OSTYPE not supported .."
  exit -1
fi


# EOF
